package day3;

import java.util.Arrays;

import org.junit.Test;

public class BubbleSort {

	@Test
	public void test1() {
		int num1 = 3;
		int num2 = 5;
		System.out.println("num1 before:" + num1);
		System.out.println("num2 before:" + num2);
		int temp = num1;
		num1 = num2;
		num2 = temp;
		System.out.println("num1 after:" + num1);
		System.out.println("num2 after:" + num2);
	}
	
	
	
	public static void main(String[] args) {
		int[] array = {40,17,21,1};
		// 外层循环控制比较多少趟
		for (int i = 1; i <= array.length - 1; i++) {
			// 内存循环控制这一趟比较多少次
			for (int j = 0; j < array.length - i; j++) {
				// 如果左边的数比右边的数大，就交换这两个数的值
				if (array[j] > array[j + 1]) {
					int temp = array[j];
					array[j] = array[j + 1];
					array[j + 1] = temp;
				}
			}
		}
		
		for (int i = 0; i < array.length; i++) {
			System.out.println(array[i]);
		}
		
		// Arrays.sort(array);
	}
	
	
	
	
	
}
